/*
File written by Emily Smith-Greenaway, Associate Professor of Sociology, USC (smithgre@usc.edu)
This file reproduces findings reported in: 
Smith-Greenaway, Emily and Abigail Weitzman. 2020. Sibling Mortality Burden in Low-Income Countries:
A Descriptive Analysis of Sibling Death in Africa, Asia, and Latin America and the Caribbean, 
PLOS One.  
The data required to run this do-file are publicly available at dhsprogram.com (user must register for data)
This do-file generates three, separate regional datasets that are then used in "2_Smith-GreenawayWeitzman2020PLOSOne_replication_generate_estimates.do"
to reproduce all findings. 
*/


*******************************
*******************************
*******************************
*******************************
*******************************
*******************************
************SUB-SAHARAN AFRICA
*******************************
*******************************
*******************************
*******************************
*******************************
*******************************
clear all 
macro drop _all
local tag "sib" 
local varlist "caseid mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20 "

tempfile AOIR71FL 
use `varlist' using AOIR71FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 1.dta , replace
*
tempfile BFIR62FL
use `varlist' using BFIR62FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 2.dta  , replace 
*
tempfile BJIR71FL
use `varlist' using BJIR71FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 3.dta  , replace 
*
tempfile BUIR70FL
use `varlist' using BUIR70FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 4.dta  , replace 
*
tempfile CDIR61FL
use `varlist' using CDIR61FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20   caseid
save 5.dta  , replace 
*
tempfile CGIR60FL
use `varlist' using CGIR60FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 6.dta  , replace 
*
tempfile CIIR62FL
use `varlist' using CIIR62FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 7.dta  , replace 
*
tempfile CMIR61FL
use `varlist' using CMIR61FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 8.dta  , replace 
*
tempfile ETIR70FL
use `varlist' using ETIR70FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 9.dta  , replace 
*
tempfile GAIR60FL
use `varlist' using GAIR60FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 10.dta  , replace 
*
tempfile GMIR60FL
use `varlist' using GMIR60FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 11.dta  , replace 
*
tempfile GNIR62FL
use `varlist' using GNIR62FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 12.dta  , replace 
*
tempfile szir51fl
use `varlist' using szir51fl.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 13.dta  , replace 
*
tempfile KEIR71FL
use `varlist' using KEIR71FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 14.dta  , replace 
*
tempfile KMIR61FL
use `varlist' using KMIR61FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 15.dta  , replace 
*
tempfile LSIR71FL
use `varlist' using LSIR71FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 16.dta  , replace 
*
tempfile MDIR51FL
use `varlist' using MDIR51FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 17.dta  , replace 
*
tempfile MLIR6AFL
use `varlist' using MLIR6AFL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 18.dta  , replace 
*
tempfile MWIR7HFL
use `varlist' using MWIR7HFL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 19.dta  , replace 
*
tempfile NGIR6AFL
use `varlist' using NGIR6AFL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 20.dta  , replace 
*
tempfile NIIR61FL
use `varlist' using NIIR61FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 21.dta  , replace 
*
tempfile NMIR61FL
use `varlist' using NMIR61FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 22.dta  , replace 
*
tempfile RWIR70FL
use `varlist' using RWIR70FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 23.dta  , replace 
*
tempfile SLIR61FL
use `varlist' using SLIR61FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 24.dta , replace
*
tempfile SNIR7ZFL
use `varlist' using SNIR7ZFL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 25.dta  , replace 
*
tempfile STIR50FL
use `varlist' using STIR50FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 26.dta  , replace 
*
tempfile TDIR71FL
use `varlist' using TDIR71FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 27.dta  , replace 
*
tempfile TGIR61FL
use `varlist' using TGIR61FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 28.dta  , replace 
*
tempfile TZIR7AFL
use `varlist' using TZIR7AFL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 29.dta  , replace 
*
tempfile UGIR7AFL
use `varlist' using UGIR7AFL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 30.dta  , replace 
*
tempfile LBIR6AFL
use `varlist' using LBIR6AFL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 31.dta  , replace 
*
tempfile ZAIR71FL
use `varlist' using ZAIR71FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 32.dta  , replace 
*
tempfile ZMIR61FL
use `varlist' using ZMIR61FL.dta, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 33.dta , replace  
*
tempfile ZWIR71FL
use `varlist' using ZWIR71FL.DTA, clear 
keep mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20  caseid
save 34.dta , replace 

clear
use 1.dta 
append using 2.dta
append using 3.dta
append using 4.dta
append using 5.dta
append using 6.dta
append using 7.dta
append using 8.dta
append using 9.dta
append using 10.dta
append using 11.dta
append using 12.dta
append using 13.dta
append using 14.dta
append using 15.dta 
append using 16.dta
append using 17.dta
append using 18.dta
append using 19.dta
append using 20.dta
append using 21.dta
append using 22.dta
append using 23.dta
append using 24.dta
append using 25.dta
append using 26.dta
append using 27.dta
append using 28.dta
append using 29.dta
append using 30.dta
append using 31.dta
append using 32.dta
append using 33.dta
append using 34.dta

gen svyweight = v005/1000000
gen strata = v022
svyset [pweight=svyweight], psu(v001) strata(strata) 

gen country_=v000
replace country_="Angola" 					if country=="AO7"
replace country_="Burkina Faso" 			if country=="BF6"
replace country_="Benin" 					if country=="BJ7"
replace country_="Burundi" 					if country=="BU7"
replace country_="DRC" 						if country=="CD6"
replace country_="Congo" 					if country=="CG6"
replace country_="Cote d'Ivoire" 			if country=="CI6"
replace country_="Cameroon" 				if country=="CM6"
replace country_="Ethiopia" 				if country=="ET7" 
replace country_="Gabon" 					if country=="GA6"
replace country_="Gambia" 					if country=="GM6"
replace country_="Guinea" 					if country=="GN6"
replace country_="Kenya" 					if country=="KE6" 
replace country_="Comoros" 					if country=="KM6"
replace country_="Liberia" 					if country=="LB6" 
replace country_="Lesotho" 					if country=="LS6" 
replace country_="Madagascar" 				if country=="MD5"
replace country_="Mali" 					if country=="ML6" 
replace country_="Malawi" 					if country=="MW7"
replace country_="Nigeria" 					if country=="NG6"
replace country_="Niger" 					if country=="NI6" 
replace country_="Namibia" 					if country=="NM6"
replace country_="Rwanda" 					if country=="RW6"
replace country_="Sierra Leone" 			if country=="SL6" 
replace country_="Senegal" 					if country=="SN7" 
replace country_="Sao Tome Principe" 		if country=="ST5" 
replace country_="Eswatini" 				if country=="SZ5" 
replace country_="Chad" 					if country=="TD6" 
replace country_="Togo" 					if country=="TG6"
replace country_="Tanzania" 				if country=="TZ7" 
replace country_="Uganda" 					if country=="UG7"
replace country_="South Africa" 			if country=="ZA7" 
replace country_="Zambia" 					if country=="ZM6"
replace country_="Zimbabwe" 				if country=="ZW7"         

gen country=v000
gen westflag=0
replace westflag=1 if country=="BF6"
replace westflag=1 if country=="BJ7"
replace westflag=1 if country=="CI6"
replace westflag=1 if country=="CM6"
replace westflag=1 if country=="GM6"
replace westflag=1 if country=="GN6"
replace westflag=1 if country=="LB6" 
replace westflag=1 if country=="ML6" 
replace westflag=1 if country=="NG6"
replace westflag=1 if country=="NI6" 
replace westflag=1 if country=="SL6" 
replace westflag=1 if country=="SN7" 
replace westflag=1 if country=="TG6"

gen eastflag=0
replace eastflag=1 if country=="BU7"
replace eastflag=1 if country=="ET7" 
replace eastflag=1 if country=="KE6" 
replace eastflag=1 if country=="MD5"
replace eastflag=1 if country=="RW6"
replace eastflag=1 if country=="TZ7" 
replace eastflag=1 if country=="UG7"
replace eastflag=1 if country=="KM6"

gen centralflag=0
replace centralflag=1 if country=="CD6"
replace centralflag=1 if country=="CG6"
replace centralflag=1 if country=="GA6"
replace centralflag=1 if country=="TD6" 
replace centralflag=1 if country=="ST5" 

gen southflag=0 
replace southflag=1 if country=="AO7"
replace southflag=1 if country=="LS6" 
replace southflag=1 if country=="MW7"
replace southflag=1 if country=="NM6"
replace southflag=1 if country=="SZ5" 
replace southflag=1 if country=="ZA7" 
replace southflag=1 if country=="ZM6"
replace southflag=1 if country=="ZW7"  

replace mmc1=0 if mmc1==. & country_=="Eswatini"
replace mmc1=0 if mmc1==. & country_=="Liberia"
sort country_
by country_: tab mmc1, missing
recode mmc1 99=.
replace mmc1=mmc1-1 if country_=="South Africa"
drop if mmc1==. 

gen group=1 	if westflag==1
replace group=2 if centralflag==1
replace group=3 if eastflag==1
replace group=4 if southflag==1

save "append_ssa.dta", replace

*******************************
*******************************
*******************************
*******************************
*******************************
*******************************
***************************ASIA
*******************************
*******************************
*******************************
*******************************
*******************************
*******************************
clear all 
macro drop _all
local tag "sib" 
local varlist "caseid mmc1 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20"

tempfile KHIR73FL
use `varlist' using KHIR73FL.dta, clear 
keep mmc1 v000 v005 v022 v001 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20 caseid
save 1.dta  , replace 
*
tempfile MMIR71FL
use `varlist' using MMIR71FL.dta, clear 
keep mmc1 v000 v005 v022 v001 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20 caseid
save 2.dta  , replace 
*
tempfile NPIR7HFL
use `varlist' using NPIR7HFL.dta, clear 
keep mmc1 v000 v005 v022 v001 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20 caseid
save 3.dta  , replace 
*
tempfile TLIR71FL
use `varlist' using TLIR71FL.dta, clear 
keep mmc1 v000 v005 v022 v001 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20 caseid
save 4.dta  , replace 

clear
use 1.dta 
append using 2.dta
append using 3.dta
append using 4.dta

gen country_=v000
replace country_="Cambodia" 	if country=="KH6"
replace country_="Myanmar" 		if country=="MM7"
replace country_="Nepal" 		if country=="NP7"
replace country_="Timor-Leste" 	if country=="TL7"

gen svyweight = v005/1000000
gen strata = v022
svyset [pweight=svyweight], psu(v001) strata(strata) 

gen group=5

replace mmc1=0 if country_=="Myanmar" & mmc1==. 

save "append_asia.dta", replace

 
*******************************
*******************************
*******************************
*******************************
*******************************
*******************************
******************LATIN AMERICA
*******************************
*******************************
*******************************
*******************************
*******************************
*******************************
clear all 
macro drop _all
local tag "sib" 
local varlist "caseid mmc1 v005 v022 v001 v000 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20  mm6_01-mm6_20 mm7_01-mm7_20"

tempfile HTIR70FL
use `varlist' using HTIR70FL.dta, clear 
keep mmc1 v000 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20  mm6_01-mm6_20 caseid
save 1.dta , replace 
*
tempfile PEIR6IFL
use `varlist' using PEIR6IFL.dta, clear 
keep mmc1 v000 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20 mm7_01-mm7_20 caseid
save 2.dta  , replace 
*
tempfile BOIR51FL
use `varlist' using BOIR51FL.dta, clear 
keep mmc1 v000 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20 caseid
save 3.dta  , replace 
*
tempfile COIR72FL
use `varlist' using COIR72FL.dta, clear 
keep mmc1 v000 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20 caseid
save 4.dta  , replace 
*
tempfile GUIR71FL
use `varlist' using GUIR71FL.dta, clear 
keep mmc1 v000 v005 v022 v001 v000 v007 v012 mm4_01-mm4_20 mm1_01-mm1_20 mm6_01-mm6_20 caseid
save 5.dta , replace 

clear
use 1.dta 
append using 2.dta
append using 3.dta
append using 4.dta
append using 5.dta

gen country_=v000
replace country_="Bolivia" 	if country=="BO5"
replace country_="Colombia" 	if country=="CO7"
replace country_="Guatemala" if country=="GU6"
replace country_="Haiti" 	if country=="HT7"
replace country_="Peru" 		if country=="PE6"

gen svyweight = v005/1000000
gen strata = v022
svyset [pweight=svyweight], psu(v001) strata(strata) 

gen group=6

replace mmc1=0 if mmc1==. & country_=="Guatemala"
replace mmc1=0 if mmc1>=98 & mmc1<=99
drop if mmc1==. 

save "append_latinamerica.dta", replace
